package net.janeluo.rs.service;

import java.util.List;

import net.janeluo.rs.entity.RS_Shops;

import org.apache.commons.lang.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.service.Service;

/**
 * 店铺管理处理业务类
 * 
 * @author DLK)YangYining
 * @version 1.0.0
 */
@IocBean(fields = { "dao" })
public class ShopsManagerService extends Service {
    private static final Log log = Logs.getLog(ShopsManagerService.class);
    
    public ShopsManagerService() {
        super();
    }

    public ShopsManagerService(Dao dao) {
        super(dao);
    }
    
    /**
     * 店铺新增
     * 
     * @param entity 店铺实体
     * @return 店铺实体
     */
    public RS_Shops insertShop(RS_Shops entity){
        return dao().insert(entity);
    }
    
    /**
     * 店铺更新
     * 
     * @param entity 店铺实体
     * @return 店铺实体
     */
    public int updateShop(RS_Shops entity){
        return dao().update(entity);
    }
    
    /**
     * 根据店铺id查询店铺
     * 
     * @param sid 店铺id
     * @return 店铺信息实体
     */
    public RS_Shops findShopById(Integer sid) {
        return dao().fetch(RS_Shops.class, sid);
    }
    
    /**
     * 根据店铺id查询店铺
     * 
     * @param sid 店铺id
     * @return 店铺信息实体
     */
    public void deleteShop(Integer sid) {
        dao().delete(RS_Shops.class, sid);
    }
    
    /**
     * 根据店铺id查询店铺
     * 
     * @param sidarr 店铺id集合
     * @return 店铺信息实体
     */
    public void deleteShops(Integer[] sidarr) {
        dao().clear(RS_Shops.class, Cnd.where("sid", "in", sidarr));
    }
    
    /**
     * 查询店铺列表 
     * 
     * @param shopName 店铺名称
     * @return
     */
    public List<RS_Shops> getShopList (String shopName){
        log.debug("================= 查询列表处理开始 ==================");
        
        Criteria cri = Cnd.cri();
        if (StringUtils.isNotEmpty(shopName)) {
            cri.where().andLike("sname", "%" + shopName + "%");
        }
        cri.getOrderBy().asc("sname");
        List<RS_Shops> list = dao().query(RS_Shops.class, cri);
        log.debug("================= 查询列表处理结束 ==================");
        return list;  
    }
}
